import random

from django.contrib import admin
from django.db import models

from apps.baseData.models import User, BaseModel, District
from apps.fontend.models import Classify


class Images(BaseModel):
    url = models.CharField(max_length=255, verbose_name="类型的名字")
    need = models.ForeignKey('Need', related_name="images", on_delete=models.CASCADE, verbose_name="需求的外键")

    class Meta:
        verbose_name = '图片表'
        verbose_name_plural = verbose_name


class Video(BaseModel):
    url = models.CharField(max_length=255, verbose_name="类型的名字")
    need = models.ForeignKey('Need', related_name="video", on_delete=models.CASCADE, verbose_name="需求的外键")

    class Meta:
        verbose_name = '需求帖子的视频地址'
        verbose_name_plural = verbose_name


class Need(BaseModel):
    """
    需求
    """
    STATUS_CHOICES = (
        (0, "待审核"),
        (1, "待接单"),
        (2, "派送中"),
        (3, "已完成"),
        (4, "已下架"),
    )
    title = models.CharField(max_length=255, verbose_name="需求的标题")
    content = models.TextField(max_length=255, verbose_name="需求的内容题")
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="发布的用户id")
    money = models.FloatField(default=1, verbose_name="悬赏金额")
    classify = models.ForeignKey(Classify, on_delete=models.CASCADE, verbose_name="需求的类型id")
    location = models.CharField(max_length=255, verbose_name="定位的经纬度")
    status = models.IntegerField(choices=STATUS_CHOICES, default=0, verbose_name="订单状态")
    address = models.CharField(max_length=255, null=True, verbose_name="详细地址")
    phone = models.CharField(max_length=11, null=True, verbose_name="联系电话")
    # 收货码
    receiving_code = models.CharField(max_length=6, verbose_name='收货码', default=random.randint(100000, 999999))

    class Meta:
        db_table = 'need'
        verbose_name = '需求表'
        verbose_name_plural = verbose_name


class Tags(BaseModel):
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="发表的用户")
    name = models.CharField(max_length=5, verbose_name="发表的自定义tag")
    need = models.ForeignKey(Need, related_name='tags', on_delete=models.CASCADE, null=True, verbose_name="绑定的帖子")

    class Meta:
        verbose_name = '自定义标记'
        verbose_name_plural = verbose_name


admin.site.register([Images, Video, Tags, Need])
